/**
 * Created by kangdaye on 16/6/5.
 */

//Main
app.controller('userListCtr',["$scope","ngDialog","confirm","message","userListCache","userListService", function($scope,ngDialog,confirm,message,userListCache,userListService) {
    $scope.gridOptions = {
        url          : servicePath + 'user/list',
        columnDefs   : userListCache.listTableHeader,
        selectAll    : true
    };

    $scope.delete = function(id){
        confirm({
            text:'确定要删除吗？',
            option:{
                go:function(){
                    var selectIds = angular.add($scope.gridOptions.selectData,'id');
                    userListService.delete({
                        ids : id || selectIds.toString()
                    },function(){
                        $scope.gridOptions.refresh();
                        message({text : '删除成功'});
                    });
                }
            }
        });
    };

    $scope.addEdit = function(model){
        ngDialog.open({
            template: '/admin/view/other/userList/userListAEDialog.html',
            width: 480,
            controller: 'userListAEDialogCtr',
            resolve: {
                gridOpt : function(){
                    return $scope.gridOptions
                },
                addEditModel: function(){
                    return model
                }
            }
        });
    };
    
}]);
